package com.meatball.game.data

import com.fasterxml.jackson.annotation.JsonIgnore
import io.swagger.v3.oas.annotations.media.Schema
import org.springframework.web.socket.WebSocketSession

/**
 * TODO 房间内用户信息
 *
 * @property id 唯一标志
 * @property name 名词
 * @property avatar 头像
 * @property session 会话信息
 */
@Schema(description = "玩家信息")
data class RoomUser (
        @Schema(description = "玩家ID", example = "512d63af0df24cd0be7e66a387da914c")
        val id: String,
        @Schema(description = "玩家名称", example = "李明")
        val name: String,
        @Schema(description = "玩家头像", example = "https://meatball.org.cn:8000/images/2024/03/07/v2-96e38ba70a23189737b0dca1d8fb315f_r.jpg")
        val avatar: String,
        @JsonIgnore
        val session: WebSocketSession? = null,
        @Schema(description = "是否是AI(true/false)", example = "true")
        val isAi: Boolean = false
)

/**
 * TODO 房间数据类
 *
 * @property id 房间ID
 * @property users 用户列表
 */
data class Room(
        val id: String,
        val maxUsers: Int,
        val isRealUser: Boolean,
        val users: MutableList<RoomUser> = mutableListOf()
) {
    /**
     * TODO 判断房间是否满了
     *
     * @return
     */
    fun isFull() : Boolean {
        return if (isRealUser) {
            users.size >= maxUsers
        } else {
            users.size >= maxUsers - 1
        }
    }
}
